Implementing `fling` logic without pan gesture recognizers

Posted by KDiTraglia on Game Development See other posts from Game Development or by KDiTraglia
Published on 2013-11-07T13:22:33Z Indexed on 2013/11/07 16:14 UTC
Read the original article Hit count: 246

Filed under:
|
|

So I am trying to port over a simple game that I originally wrote to iphone into cocos2d-x. I've hit a minor bump however in implementing simple 'fling' logic I had in the iphone version that is difficult to port over to the c++. In iOS I could get the velocity of a pan gesture very easily:

CGPoint velocity = [recognizer velocityInView:recognizer.view]; 

However now I basically only know where the touch began, where the touch ended, and all the touches that are logged in between. For now I logged all the pts onto a stack then pulled the last point and the 6th to last point (seemed to work the best), find the difference between those pts multiply by a constant and use that as the velocity. It works relatively well, but I'm wondering if anyone else has any better algorithms, when given a bunch of touch pts, to figure out a new speed upon releasing an object that feels natural (Note speed in my game is just a constant x and y, there's no drag or spin or anything tricky like that).

Bonus points if anyone has figured out how to get pan gestures into the newest version (3.0 alpha) of cocos2d-x without losing ability to build cross platform.

© Game Development or respective owner

Related posts about c++

Related posts about cocos2d-x